package com.ruicar.afs.cloud.admin.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.ruicar.afs.cloud.common.core.security.vo.UserVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * The type SysUser.
 * <p>
 * Created on 2019-02-20
 *
 * @author Fzero
 */
@Data
@TableName("sys_user")
public class SysUser implements Serializable {

	/**
	 * The constant serialVersionUID.
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * The User id.
	 */
	@TableId(value = "user_id")
	private Long userId;
	/**
	 * The Username.
	 */
	private String username;

	/**
	 * The User real name.
	 */
	@TableId(value = "user_real_name")
	private String userRealName;
	/**
	 * The Password.
	 */
	private String password;
	/**
	 * The Create time.
	 */
	private Date createTime;
	/**
	 * The Update time.
	 */
	private Date updateTime;
	/**
	 * The Del flag.
	 */
	@TableLogic
	private String delFlag;

	/**
	 * The Lock flag.
	 */
	private String lockFlag;

	/**
	 * The Phone.
	 */
	private String phone;
	/**
	 * The User email.
	 */
	@TableId(value = "user_email")
	private String userEmail;

	/**
	 * The Dept id.
	 */
	private Long deptId;

	private String tenantId;

	@JsonSerialize(using= ToStringSerializer.class)
	@JSONField(serializeUsing = com.alibaba.fastjson.serializer.ToStringSerializer.class)
    /** 密码最后修改时间 */
    private Long lastPassChangeTime ;
    /** 密码错误次数 */
    private Integer passErrorCount ;
	/** 最后登录失败时间 */
	private Long lastLoginFailTime ;
	/**自动登出时间，负数取系统参数值*/
	private Integer autoLogOutTime;
	@TableField(exist = false)
	@ApiModelProperty(value = "所属部门名称")
	private String departmentTitle;

	@TableField(exist = false)
	@ApiModelProperty(value = "用户拥有角色")
	private List<SysRole> roles;

	@TableField(exist = false)
	@ApiModelProperty(value = "用户拥有的权限")
	private List<SysPermission> permissions;

	public UserVo transToUserVo(){
		UserVo rtnvo= new UserVo();
		BeanUtils.copyProperties(this,rtnvo);
		return rtnvo;
	}
}
